local g = vim.g

local M = {}
M.get_minuet_config = function()
    return {
        n_completions = 1,
        virtualtext = {
            auto_trigger_ft = {
                'lua', 'python', 'javascript',
            },
            keymap = {
                accept = '<M-a>',
                dismiss = '<M-d>',
            },
            show_on_completion_menu = false,
        },
        blink = {
            enable_auto_complete = true,
        },
        provider = 'openai_fim_compatible',
        provider_options = {
            openai_fim_compatible = {
                api_key = 'DEEPSEEK_API_KEY',
                name = 'deepseek',
                optional = {
                    max_tokens = 256,
                    top_p = 0.9,
                },
            },
        },
    }
end

M.get_blink_config = function()
    local disabled_filetypes = {
        'text',
        'help',
    }
    local source_icons = {
        buffer = '',
        lsp = "",
        minuet = '',
        snippets = '',
        fallback = '',
    }
    local sources = { 'buffer','snippets','lsp','minuet' }
    return {
        enabled = function()
            local filetype = vim.bo.filetype
            for _, ft in ipairs(disabled_filetypes) do
                if filetype == ft then
                    return false
                end
            end
            return true
        end,
        cmdline = { enabled = false },
        keymap = {
            preset = 'none',
            ['<CR>'] = { 'accept', 'fallback' },
            ['<Tab>'] = { 'select_next' },
            ['<S-Tab>'] = { 'select_prev' },
            ['<C-e>'] = { 'cancel','cancel' },
        },
        sources = {
            default = sources,
            providers = {
                snippets = {
                    score_offset = -3,
                    fallbacks = {},
                },
                buffer = {
                    score_offset = -10,
                    fallbacks = {},
                },
                minuet = {
                    name = 'minuet',
                    module = 'minuet.blink',
                    async = true,
                    timeout_ms = 3000,
                    score_offset = 50,
                },
            },
        },
        signature = { enabled = false },
        cmdline = {
            completion = {
                menu = { auto_show = true },
            },
        },
        fuzzy = { implementation = "rust" },
        appearance = {
            nerd_font_variant = 'mono',
            use_nvim_cmp_as_default = true, -- menu as default, disables virtualtext
            nerd_font_variant = 'normal',
            kind_icons = kind_icons
        },
        completion = {
            trigger = { prefetch_on_insert = false },
            documentation = {
                auto_show = true,
                auto_show_delay_ms = 300,
                window = {
                    border = 'none'
                }
            },
            menu = {
                draw = {
                    columns = {
                        { 'label', gap = 1 },
                        { 'source_icon' },
                    },
                    components = {
                        source_icon = {
                            ellipsis = false,
                            text = function(ctx)
                                return source_icons[ctx.source_name:lower()] or source_icons.fallback
                            end,
                            highlight = 'BlinkCmpSource',
                        },
                        label = {
                            width = { fill = true, max = 160 },
                        },
                    },
                },
            },
        }
    }
end

return M
-- EOP
